#include <iostream>
#include "unp.h"
using namespace std;

#include "apueerror.h"
#include "mysocket.h"


int main( int argc, char **argv )
{
	int	listenfd, connfd;
	struct sockaddr_in  servaddr;
	char buff[MAXLINE];

	time_t ticks;

	listenfd = Socket( AF_INET, SOCK_STREAM, 0 );

	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
	servaddr.sin_port = htons( 9325 );

	if ( bind( listenfd, (SA *)&servaddr, sizeof(servaddr)) != 0 )
	{
		err_sys( "bind error!" );
	}

	if ( ( listen( listenfd, LISTENQ )) != 0 )
	{
		err_sys( "listen error!" );
	}

	
	//connfd = accept( listenfd, (SA *) NULL, NULL );
	for ( ; ; )
	{
		connfd = accept( listenfd, (SA *) NULL, NULL );
		
		ticks = time(NULL);

		snprintf( buff, sizeof(buff), "%.24s\r\n", ctime(&ticks) );
		write( connfd, buff, strlen(buff) );
	}
	
	return 0;
}
